home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / displytl / file.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  10.6 KB  |  317 lines

  1. /*
  2.  * Copyright (c) 1990, 1991, 1992 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23. /* $Header: /Source/Media/collab/DisplayTool/RCS/file.c,v 1.11 93/02/07 17:51:02 drapeau Exp $ */
  24. /* $Log:    file.c,v $
  25.  * Revision 1.11  93/02/07  17:51:02  drapeau
  26.  * Cosmetic changes, added calls to UpdateHeader() to indicate status of
  27.  * currently open document.
  28.  * 
  29.  * Revision 1.1  92/10/29  13:54:32  drapeau
  30.  * Initial revision
  31.  *  */
  32. static char dtFile[] = "$Header: /Source/Media/collab/DisplayTool/RCS/file.c,v 1.11 93/02/07 17:51:02 drapeau Exp $";
  33.  
  34. #include "DisplayTool.h"
  35. #include "externs.h"
  36.  
  37.  
  38.  
  39. int 
  40.   OpenEditFile(void)
  41. {
  42.   int    i, counter, temp1, temp2;
  43.   int    totalNumberOfImages = 0;
  44.   char    message[MaxLength];
  45.   char    line[MAXPATHLEN];
  46.   char    fileType[MaxLength];
  47.   char*    tempFilename;
  48.   char*    tempDuration;
  49.   char*    tempLabel;
  50.   FILE*    fp;
  51.   
  52.   fp = (FILE *)fopen(currentFilename, "r");
  53.   fscanf (fp, "#%s Document#\n", fileType);            
  54.   if (strcmp(fileType, "DisplayTool"))                
  55.     {                                
  56.       sprintf (message, "'%s' is not an DisplayTool list\n", currentFilename);
  57.       notice_prompt(baseWindow->baseWindow, NULL,
  58.             NOTICE_MESSAGE_STRINGS,
  59.             message,
  60.             NULL,
  61.             NOTICE_BUTTON_YES, "OK",
  62.             NULL);
  63.       return None;
  64.       fclose(fp);
  65.     }
  66.   fscanf (fp, "#Number of Slides:\t%d\n", &temp1);        
  67.   numSlides = temp1;
  68.   fscanf (fp, "#Number of Images:\t%d\n", &temp1);        
  69.   numSlidesImages = temp1;
  70.   for (counter=0; counter<numSlides; counter++)
  71.     {
  72.       fgets(line,512,fp);                        /* skip the #Slide: */                              
  73.       fgets(line,512,fp);                                    
  74.       tempLabel = &line[9];
  75.       tempLabel[strlen(tempLabel)-1] = '\0';            
  76.       slide[counter]->label = (char *)strdup(tempLabel);                    
  77.       fgets(line,512,fp);                                    
  78.       tempDuration = &line[11];
  79.       tempDuration[strlen(tempDuration)-1] = '\0';            
  80.       slide[counter]->duration = (char *)strdup(tempDuration);                    
  81.       fscanf (fp, "#NumImages:\t%d\n", &temp1);        
  82.       slide[counter]->numberOfImages = temp1;
  83.       for (i=0; i<slide[counter]->numberOfImages; i++)
  84.     {
  85.       dtImage[totalNumberOfImages] = (IMAGE)malloc(sizeof(struct ImageStruct));
  86.       NullFields(dtImage[totalNumberOfImages]);
  87.       fgets(line,MAXPATHLEN,fp);                                    
  88.       tempFilename = &line[11];
  89.       tempFilename[strlen(tempFilename)-1] = '\0';            
  90.       dtImage[totalNumberOfImages]->filename = (char *)strdup(tempFilename);
  91.       fscanf (fp, "#LocXY:\t\t%d %d\n", &temp1, &temp2);        
  92.       dtImage[totalNumberOfImages]->corner.x = (int)(temp1/largeFactor);
  93.       dtImage[totalNumberOfImages]->corner.y = (int)(temp2/largeFactor);
  94.       fscanf (fp, "#WidthHeight:\t%d %d\n", &temp1, &temp2);        
  95.       dtImage[totalNumberOfImages]->largeWidth = (int)temp1;
  96.       dtImage[totalNumberOfImages]->largeHeight = (int)temp2;
  97.       dtImage[totalNumberOfImages]->slide = counter;
  98.       slide[counter]->imageIds[i] = totalNumberOfImages++;
  99.     }
  100.     } 
  101.   fclose(fp);
  102.   SetCurrentSlide(0);
  103.   sprintf(message, "Total Number of Slides :  %d", numSlides);
  104.   xv_set(baseWindow->totalNumberOfSlidesMessage, PANEL_LABEL_STRING, 
  105.      message, NULL);
  106.   if ((int)xv_get(slidesScrollbar, SCROLLBAR_VIEW_START) != 0)
  107.     xv_set(slidesScrollbar, SCROLLBAR_VIEW_START, 0, NULL); 
  108.   changes = False; 
  109.   UpdateHeader(False);
  110.   return(0);
  111. }                                    /* end function OpenEditFile */
  112.  
  113.  
  114.  
  115.  
  116.  
  117. int                                            /* browser code */
  118.   OpenHandler(char *proposedPath, int id)
  119. {
  120.   char temp[MaxLength];
  121.   int i, j;
  122.   
  123.   if (id != 0)                                /* Was this a request to open a DisplayTool document? */
  124.     {                                    /* Yes, continue */
  125.       if (strstr(proposedPath, "untitled") == NULL && strlen(proposedPath) > 0) 
  126.     {
  127.       if (verbose)
  128.         printf("Opening Edit List: %s\n", proposedPath);
  129.       strcpy(currentFilename, proposedPath);
  130.       sprintf(temp, "DisplayTool Document :  \"%s\"", proposedPath);
  131.       xv_set(baseWindow->baseWindow, XV_LABEL, temp, NULL);
  132.       if (numSlidesImages > 0)
  133.         ClearAll(NULL, MENU_NOTIFY);
  134.       if (slideSize != Small)
  135.         ShowFullSize(NULL, Small, NULL);
  136.       OpenEditFile();
  137.       theCmap = slidesCmap;
  138.       theDisp = display;
  139.       if (performing == 0)                        /* Only load all slides if not in performance mode; i.e.,... */
  140.         for (i=0; i<numSlides; i++)                    /* ...if not being called by another MAEstro application */
  141.           DisplayImages(i);
  142.       previousSlide = 0;
  143.       selectedSlide = 0;
  144.       SetCurrentSlide(1);
  145.       xv_set(slidePopup->duration, PANEL_VALUE, slide[selectedSlide]->duration, NULL);
  146.       if (slide[selectedSlide]->label)
  147.         if (strncmp(slide[selectedSlide]->label, "No Label", 8) != 0)
  148.           xv_set(slidePopup->label, PANEL_VALUE, slide[selectedSlide]->label, NULL);
  149.         else
  150.           xv_set(slidePopup->label, PANEL_VALUE, "", NULL);
  151.       RedrawRectangles();
  152.       SlidesRepaint(NULL, NULL, NULL, NULL); 
  153.     }
  154.     }
  155.   else                                    /* No, don't open a DisplayTool document; instead, open... */
  156.     LoadGalleryImage(proposedPath);                    /* ...an image to put in the gallery */
  157.   return 0;
  158. }                                    /* end function OpenHandler */
  159.  
  160. int                                    /* Browser code */
  161.   SaveHandler(char *proposedPath, int id)
  162. {
  163.   char temp[MaxLength];
  164.   if (strstr(proposedPath, "untitled") == NULL && strlen(proposedPath) > 0) 
  165.     {
  166.       CheckGeometry();
  167.       strcpy(currentFilename, proposedPath);
  168.       WriteSequenceToFile();
  169.       return 0;
  170.     }
  171.   else
  172.     {
  173.       sprintf(temp, "Can't save to %s.\n", proposedPath);
  174.       notice_prompt(baseWindow->baseWindow, NULL,
  175.             NOTICE_MESSAGE_STRINGS,
  176.             temp,
  177.             "Try saving to a different name.",
  178.             NULL,
  179.             NOTICE_BUTTON_YES, "OK",
  180.             NULL);
  181.       return None;
  182.     }
  183. }
  184.  
  185. void WriteSequenceToFile(void)
  186. {
  187.   FILE *fp, *fpRead;
  188.   char fileType[MaxLength];
  189.   int response, imageNum, slideNum;
  190.   int i, counter;
  191.   int maxSlide;
  192.   char message[MaxLength];
  193.   if (strstr(currentFilename, "untitled") != NULL || strlen(currentFilename) == 0) 
  194.     {
  195.       Browse(realpath(currentFilename, dummy), 
  196.          BrowseSave, NULL, "#DisplayTool Document#", "DisplayTool"); 
  197.       return;
  198.     }
  199.   if ((fpRead = fopen(currentFilename, "r")) != (FILE *)NULL)
  200.     {
  201.       fscanf (fpRead, "#%s Document#\n", fileType);    
  202.       if (strcmp(fileType, "DisplayTool"))                
  203.     {                                
  204.       sprintf (message, "'%s' exists and is not a DisplayTool list.\n", currentFilename);
  205.       response = notice_prompt(baseWindow->baseWindow, NULL,
  206.                    NOTICE_MESSAGE_STRINGS,
  207.                    message,
  208.                    "Go ahead and overwrite its contents?",
  209.                    NULL,
  210.                    NOTICE_BUTTON_NO, "Yes",
  211.                    NOTICE_BUTTON_YES, "Cancel",
  212.                    NULL);
  213.       if (response == NOTICE_YES)
  214.         {
  215.           fclose(fpRead);
  216.           return;
  217.         }
  218.     }
  219.       else
  220.     {
  221.       sprintf (message, "'%s' is already a DisplayTool list.\n", currentFilename);
  222.       response = notice_prompt(baseWindow->baseWindow, NULL,
  223.                    NOTICE_MESSAGE_STRINGS,
  224.                    message,
  225.                    "Go ahead and overwrite its contents?",
  226.                    NULL,
  227.                    NOTICE_BUTTON_NO, "Yes",
  228.                    NOTICE_BUTTON_YES, "Cancel",
  229.                    NULL);
  230.       if (response == NOTICE_YES)
  231.         {
  232.           fclose(fpRead);
  233.           return;
  234.         }
  235.     }
  236.     }
  237.   if ((fp = fopen(currentFilename, "w")) == (FILE *)NULL)
  238.     {
  239.       sprintf(message, "Can't open '%s' for writing.", currentFilename);
  240.       notice_prompt(baseWindow->baseWindow, NULL,
  241.             NOTICE_MESSAGE_STRINGS,
  242.             message,
  243.             NULL,
  244.             NOTICE_BUTTON_YES, "OK",
  245.             NULL);
  246.       fclose(fp);
  247.       return;
  248.     }
  249.   if (slideSize != Small)
  250.     {
  251.       xv_set(baseWindow->showFullSize, PANEL_VALUE, 2, NULL);
  252.       ShowFullSize(NULL, Small, NULL);
  253.       
  254.     }
  255.   if (numSlidesImages == 0)
  256.     {
  257.       notice_prompt(baseWindow->baseWindow, NULL,
  258.             NOTICE_MESSAGE_STRINGS,
  259.             "No sequence to save.",
  260.             NULL,
  261.             NOTICE_BUTTON_YES, "OK",
  262.             NULL);
  263.       return;
  264.     }
  265.   maxSlide = GetMaxSlide();
  266.   for (i=0; i<MaxNumSlides; i++)
  267.     slide[i]->numberOfImages = 0;
  268.   for (counter = 0; counter < numSlidesImages; counter ++)    
  269.     {
  270.       slideNum = dtImage[counter]->slide;
  271.       slide[slideNum]->imageIds[slide[slideNum]->numberOfImages++] = counter;
  272.     }
  273.   fprintf (fp, "#DisplayTool Document#\n");
  274.   fprintf (fp, "#Number of Slides:\t%d\n", maxSlide+1);    
  275.   fprintf (fp, "#Number of Images:\t%d\n", numSlidesImages);
  276.   for (counter = 0; counter <= maxSlide; counter ++)               
  277.     {    
  278.       fprintf(fp, "\n#Slide:\t%d\n#Label:\t\t%s\n#Duration:\t%s\n#NumImages:\t%d\n",       
  279.           counter+1, slide[counter]->label,  slide[counter]->duration, slide[counter]->numberOfImages);
  280.       for (i=0; i<slide[counter]->numberOfImages; i++)
  281.     {
  282.       imageNum = slide[counter]->imageIds[i];
  283.       fprintf(fp, "#Filename:\t%s\n#LocXY:\t\t%d %d\n#WidthHeight:\t%d %d\n",       
  284.           dtImage[imageNum]->filename, 6 * dtImage[imageNum]->corner.x, 
  285.           6 * dtImage[imageNum]->corner.y,
  286.           dtImage[imageNum]->largeWidth, dtImage[imageNum]->largeHeight);
  287.     }
  288.     }
  289.   fclose (fp);                               
  290.   changes = False; 
  291.   UpdateHeader(False);
  292.   return;
  293. }                                    /* end function WriteSequenceToFile */
  294.  
  295.  
  296.  
  297. void 
  298.   LoadGalleryImage(char *file)
  299. {
  300.   IMAGE    tempImage = (IMAGE)NULL;
  301.   
  302.   sprintf(diagString, "Entering LoadGalleryImage with filename %s.\n", file);
  303.   PrintDTDiagnostics(diagString);
  304.   theCmap = galleryCmap;
  305.   theDisp = display;
  306.   XSetLineAttributes(display, theGC, 2, LineSolid, CapProjecting, JoinMiter);
  307.   if (gallery[numGalleryImages] != (IMAGE)NULL)
  308.     PrintDTDiagnostics("In LoadGalleryImage, gallery image is already allocated.\n");
  309.   if ((gallery[numGalleryImages] =                    /* CreateImage will allocate and zero-fill an... */
  310.        CreateImage(file)) != NULL)                    /* ...IMAGE structure */
  311.     {
  312.       tempImage = gallery[numGalleryImages];
  313.       PaintGalleryImage(numGalleryImages);                /* Draw the new gallery image in the Gallery  */
  314.       numGalleryImages++;
  315.     }
  316. }                                    /* end function LoadGalleryImage */
  317.